package com.mes.inventory.service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.data.provider.Page;
import com.mes.common.service.BasicService;
import com.mes.inventory.dao.iface.IWarebinDao;
import com.mes.inventory.domain.Warebin;
@Service
public class WarebinService extends BasicService<Warebin>{
	
	@Autowired
	private IWarebinDao warebinDao;
		//柜位树
		@DataProvider
		public Collection<Warebin> getChildWarebins(Map<String,Object> parameter) throws Exception{
			
			String warehouseUid = (String)parameter.get("warehouseUid");
			Collection<Warebin> warebins = warebinDao.findByProperty("warehouseUid", warehouseUid);
			return warebins;
		}
		//柜位树
		@DataProvider
		public Collection<Warebin> getWarebins(String uuid) throws Exception{
					
			Collection<Warebin> warebins = warebinDao.findByProperty("parentBinUid", uuid);
			return warebins;
		}
		//各个库房下的柜位
		@DataProvider
		public Collection<Warebin> getWarebinsByWarehouseUid(String warehouseUid) throws Exception{
			Collection<Warebin> warebins = warebinDao.findByProperty("warehouseUid", warehouseUid);
			return warebins;
		}
		//根据id查询仓库
				@DataProvider
				public List<Warebin> getWarebins(Page<Warebin> page,Map<String, Object> parameter) throws Exception{
					if (null!=parameter) {
						String warehouseId = (String) parameter.get("warehouseUid");
						List<Warebin> list = warebinDao.findByProperty("warehouseUid", warehouseId,null);
						return list;
					}
					return null;
				}
				
				//根据仓库id查询柜位分页
				@DataProvider
			    public void getWarebinsByPage(Page<Warebin> page, Map<String, Object> parameter){
			    	if (parameter != null && !parameter.equals("") ){
			    		try {
			    			String warehouseUid = (String) parameter.get("warehouseUid");
			    			warebinDao.getWarebinsByPage(page, warehouseUid);
			    		} catch (Exception e) {
			    			e.printStackTrace();
			    		}
			    	}
			    }
				
				
				//模糊查询
				//根据id查询仓库
				@DataProvider
				public void getWarebin(Page<Warebin> page,Map<String, Object> parameter) throws Exception{
					if (null!=parameter) {
						warebinDao.getWarebin(page, parameter);
					}
					
				}
}
